# time模块

import time

# 时间戳
t = time.time()
print(t)  # 1638950715.2029195

# 延迟
time.sleep(0.4)
t1 = time.time()
print(t1)  # 1638950715.6041477

# 将时间戳转成字符串
s = time.ctime(t)
print(s)  # Wed Dec  8 16:05:15 2021

# 将时间戳转成元组的时间
t = time.localtime(t)
print(t.tm_yday)  # 342
print(
    t)  # time.struct_time(tm_year=2021, tm_mon=12, tm_mday=8, tm_hour=16, tm_min=5, tm_sec=15, tm_wday=2, tm_yday=342, tm_isdst=0)

# 将元组的时间转成时间戳
tt = time.mktime(t)
print(tt)  # 1638950715.0

# 将元组的时间转成字符串
s = time.strftime('%Y-%m-%d %H:%M:%S', t)
print(s)  # 2021-12-08 16:05:15

# 将字符串转成元组的方式
r = time.strptime('2019/12/01', '%Y/%m/%d')
print(
    r)  # time.struct_time(tm_year=2019, tm_mon=12, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=6, tm_yday=335, tm_isdst=-1)
